Java JavaScript Python C# C C++ Go Kotlin PHP Swift R Ruby TypeScript Scala SQL Perl rust VisualBasic Matlab Julia

Basics overview

Python Statements

What are Python Statements?

In Python, a statement is an instruction that the Python interpreter can execute. So, anything written in Python is a statement. Python statement ends with the token NEWLINE character, which means each line in a Python script is a statement. For example, a = 10 is an assignment statement, where a is a variable name and 10 is its value.

Types of Python Statements

There are mainly four types of statements in Python: ✦ Print Statements: The result of a print statement is a value. ✦ Assignment Statements: Assignment statements don’t produce a result, it just assigns a value to the operand on its left side. ✦ Conditional Statements: These include if, elif, and else statements. ✦ Looping Statements: These include for and while loops. ✦ Multi-Line Statements: Python statement ends with the token NEWLINE character. But we can extend the statement over multiple lines using line continuation character (\\). This is known as an explicit continuation. We can also use parentheses () to write a multi-line statement. Whatever we add inside a parentheses () will treat as a single statement even it is placed on multiple lines.

Here’s an example of Python statements:

python statements with basic example # statement 1 print('Hello') # statement 2 x = 20 # statement 3 print(x)

Output

Hello 20
In this example, we have used three statements in our program. Remember, Python uses statements to improve the readability of code and make it consistent across the wide spectrum of Python code. Consistency within one module or function is the most important.

  📌TAGS

★python ★ Statements

Tutorials